<include file="Public:header" />
<include file="Public:left" />
	<form action="" method="post" enctype="multipart/form-data" id="brandForm">
      <input type="hidden" id="id" name="id" value="{$id}">
     <section>
      <h2><strong>机构设置</strong></h2>
      <ul class="ulColumn2">
	     <li>
            <span class="item_name" style="width:120px;">标题：</span>
            <input type="text" class="textbox textbox_295" name="name" id="name" placeholder="标题..." value="{$mechanism_result.name}"/>
        </li>
       <li>
            <span class="item_name" style="width:120px;">机构分类：</span>
            <select name="mid" id="is_important">
                <option>请选择分类</option>
                <volist name="mechanism_category" id="vo">
                  <option value="{$vo.id}" <if condition="$vo.id eq $mechanism_result.mid">selected</if>>{$vo.name}</option>
                </volist>
            </select>
        </li>
        <li>
            <span class="item_name" style="width:120px;">跳转链接：</span>
            <input type="text" class="textbox textbox_295" name="href" id="name" placeholder="跳转链接..." value="{$mechanism_result.href}"/>
        </li>
        <li>
            <span class="item_name" style="width:120px;">机构图片：</span>
            <input type="file" class="textbox textbox_295" name="picture" id="picture" placeholder="机构图片..."/>
        </li>
        <li>
            <span class="item_name" style="width:120px;">排序：</span>
            <input type="text" class="textbox textbox_295" name="order" id="orders" value="{$mechanism_result.orders}" placeholder="排序..."/>
        </li>
        <li>
            <span class="item_name" style="width:120px;">电话：</span>
            <input type="text" class="textbox textbox_295" name="contact" id="orders" value="{$mechanism_result.contact}" placeholder="排序..."/>
        </li>
        <li>
            <span class="item_name" style="width:120px;">联系地址：</span>
            <input type="text" class="textbox textbox_295" name="path" id="orders" value="{$mechanism_result.path}" placeholder="排序..."/>
        </li>
        <li>
            <span class="item_name" style="width:120px;">简介：</span>
             <script id="editor" name="content" type="text/plain" style="width:700px;height:300px;margin-left:125px; margin-top:-12px;">{$mechanism_result['content']|htmlspecialchars_decode}</script>
        </li>
        <li>
          <span class="item_name" style="width:120px;"></span>
          <input type="button" class="link_btn" value="提交"/>
        </li>
      </ul>
     </section>
	 </form>
   <script>
      $(".link_btn").click(function(){
          var formData = new FormData();
          var name = $("input[name='name']").val();
          var order = $("input[name='order']").val();
          var mid = $("select[name='mid']").val();
          var href = $("input[name='href']").val();
          var contact = $("input[name='contact']").val();
          var path = $("input[name='path']").val();
          var id = $("input[name='id']").val();
          var file = $('input[name="picture"]');
          var content = ue.getContent();
          var fileObj = file.get(0).files[0];

          var reg=/^([hH][tT]{2}[pP]:\/\/|[hH][tT]{2}[pP][sS]:\/\/)(([A-Za-z0-9-~]+)\.)+([A-Za-z0-9-~\/])+$/;

          if(!reg.test(href)){
            layer.alert("这网址不是以http://https://开头，或者不是网址！");
            return false;
          }

          formData.append('name',name);
          formData.append('order',order);
          formData.append('mid',mid);
          formData.append('href',href);
          formData.append('picture',fileObj);
          formData.append('id',id);
          formData.append('path',path);
          formData.append('contact',contact);
          formData.append('content',content);

           $.ajax({
                url:"{:url('Mechanism/add')}",
                type:'POST',
                data:formData,
                async:false,
                processData:false,
                contentType:false,
                success:function(result){
                    if(result.code == '0'){
                        layer.alert(result.msg);
                    }else{
                        layer.alert(result.msg, {
                            btn: ['确定']
                        },
                        function (index, item) {
                            location.href = result.url;
                        });
                    }
                }

            });
      });
   </script>
 </div>
</section>
</body>
<script type="text/javascript">

    //实例化编辑器
    //建议使用工厂方法getEditor创建和引用编辑器实例，如果在某个闭包下引用该编辑器，直接调用UE.getEditor('editor')就能拿到相关的实例
    var ue = UE.getEditor('editor');


    function isFocus(e){
        alert(UE.getEditor('editor').isFocus());
        UE.dom.domUtils.preventDefault(e)
    }
    function setblur(e){
        UE.getEditor('editor').blur();
        UE.dom.domUtils.preventDefault(e)
    }
    function insertHtml() {
        var value = prompt('插入html代码', '');
        UE.getEditor('editor').execCommand('insertHtml', value)
    }
    function createEditor() {
        enableBtn();
        UE.getEditor('editor');
    }


</script>
</html>
